package com.example.demo.controller;

import com.example.demo.entity.Poetry;
import com.example.demo.param.QueryParam;
import com.example.demo.service.PoetryService;
import com.example.demo.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/poetry")
public class PoetryController {

    @Resource
    private PoetryService poetryService;

    /*随机获取一首诗*/
    @GetMapping("/getRandomPoetry")
    public Result getRandomPoetry() {
        Poetry randomPoetry = poetryService.getRandomPoetry();
        return Result.ok().data("randomPoetry", randomPoetry);
    }

    /*随机获取十首诗 分页*/
    @GetMapping("/getPoetryPage")
    public Result getPoetryPage(Integer pageNo) {
        List<Poetry> poetryList = poetryService.getRandomPoetryPage(pageNo);
        return Result.ok().data("poetryList", poetryList);
    }

    /*根据id查询一首诗*/
    @GetMapping("/getPoetryById")
    public Result getPoetryById(Integer id) {
        Poetry poetry = poetryService.getPoetryById(id);
        return Result.ok().data("poetry", poetry);
    }

    /*分页选择查询 作者 朝代 类型*/
    @PostMapping("/getPoetrySelectively")
    public Result getPoetrySelectively(@RequestBody QueryParam queryParam) {
        List<Poetry> poetryList = poetryService.getPoetrySelectively(queryParam);
        return Result.ok().data("poetryList", poetryList);
    }

    /*模糊查询content*/
    @GetMapping("/searchContent")
    public Result searchContent(String content,Integer pageNo) {
        List<Poetry> poetryList = poetryService.getPoetryByContent(content,pageNo);
        return Result.ok().data("poetryList", poetryList);
    }


}
